<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="fhp" tagdir="/WEB-INF/tags"%>

<fhp:layout>
	<jsp:body>
		<link href="/css/multizoom/multizoom.css" rel="stylesheet" type="text/css" />
		<link href="/css/product_view.css" rel="stylesheet" type="text/css" />
		<script src="/js/multizoom/multizoom.js" type="text/javascript" ></script>
		<script src="/js/product.view1.js" type="text/javascript" ></script>
		<script src="/js/admin.call.rest.action.js" type="text/javascript" ></script>
		
		<script>

		var  isAdmin =true;
		var isNew = true;
		/*
			function slideFocus(_img) {
		
				var d = _img.parentNode.parentNode.parentNode;
				var d1 = d.getElementsByTagName('div')[0].getElementsByTagName('img')[0];
				d1.src = _img.src;
				d1.removeAttribute("style");
				(function($) {
					$('#images_selected').addimagezoom({
						magnifiersize : [ 300, 300 ]
					});
		
				})(jQuery);
			}
		*/
		/*
			function addImage(_img) {
		
				var newSRC = prompt('input image link ');
				if (newSRC != null) {
					_img.src = newSRC;
					_img.title = "";
					slideFocus(_img);
				}
				//i.onError = revertSRC(_img,defaulSRC);
			}*/
		
			function checkEditOrFocus(_img) {
				var defaulSRC = window.location.protocol + "//" + window.location.host
						+ '/images/plus.jpg';
				if (_img.src == document.getElementById('images_selected').src
						|| _img.src == '' || _img.src == defaulSRC) {
					addImage(_img);
				} else {
					slideFocus(_img);
				}
			}
			function addFocusEven(pagination) {
				var images = pagination.getElementsByTagName('img');
				for (var i = 0; i < images.length; i++) {
					var image = images[i];
					image.setAttribute('onclick', 'checkEditOrFocus(this)');
					//image.setAttribute('ondblclick','addImage(this)');
				}
			}
			
			function getImageURLs() {
				var imageURLs = '';
				var images = document.getElementById('image_pagination')
						.getElementsByTagName('img');
				for (var i = 0; i < images.length; i++) {
					imageURLs = imageURLs + ',' + encodeURI(images[i].src);
					//alert(imageURLs);
					//alert(decodeURI(imageURLs));
				}

				if (imageURLs.length > 0) {
					imageURLs = imageURLs.substr(1);
				}
				return imageURLs;
			};
			function editProduct(node) {

				var pathname = window.location.pathname;
				var productId = pathname.split('/')[pathname.split('/').length - 1];
				
				var fieldName;
				var fieldValue

				if (node.tagName == 'IMG') {
					fieldName = 'image_urls';
					fieldValue = getImageURLs();
				} else {
					fieldName = $(node).attr('name');
					fieldValue = encodeURIComponent(node.innerHTML);
				}
				var url = "/rest/process/edit_product";
				var params = 'product_id=' + productId + '&' + fieldName
						+ '=' + fieldValue;

				Adminexecute.execute(url, params, function() {
				});
			};
			function saveProduct() {
				var pathname = window.location.pathname;
				var productName = document.getElementById('product_name').innerHTML;
				var productDescription = document
						.getElementById('product_description').innerHTML;
				var productPrice = document.getElementById('product_price').innerHTML;
				var imageURLs = getImageURLs();

				var categoryId = pathname.split('/')[pathname.split('/').length - 2];//window.location.search.substr(1);

				var url = "/rest/process/add_product";
				var params = 'category_id=' + categoryId + '&product_name='
						+ productName + '&product_price=' + productPrice
						+ '&product_description=' + productDescription
						+ '&image_urls=' + imageURLs;
				Adminexecute.execute(url, params, function(responseText) {
					var text  = eval('(' + responseText + ')');
					window.location.href = pathname.substr(pathname.length-1)+text.id;
				});
			};
			function cancelCreate(node){
				var pathname = window.location.pathname;
				window.location.href = pathname.substr(0,pathname.length-2);
			} 
		</script>


		<style>
		</style>




	<div style="border-bottom: 1px solid #DDDDDD; height: 30px;"></div>
		<section id="product_view" class="product_view">
			
		</section>

			<script>
				
				
				var pathname = window.location.pathname;
				var productId = pathname.split('/')[pathname.split('/').length - 1];
				ProductView.loadProductData('product_view', productId);
				isNew=(productId=='0');
				if(isAdmin){
					if(isNew){
						ProductView.reRenderCreateProduct();
					}else{
						ProductView.reRenderEditProduct();
					}
					
				}else{
					ProductView.reRender();
				}	
				

				//Add Parram, edit action

				//eval('alert(pathname);');
			</script>
			
		<fhp:carouselForGallery galleryId="" galleryName="40name" />

	
	
	
	</jsp:body>

</fhp:layout>